/**
 * 
 */
package com.jiang.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


/**
 * @author Administrator
 * @验证后台未登录的时候的过滤器
 */
@WebFilter(filterName="frontAdminFilter", urlPatterns={"/pages/front/*", "/pages/admin_change_password.jsp"})
public class FrontAdminFilter implements Filter {

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {

	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		
		// 验证是否登录过，没登录过要跳转到登录页
		HttpServletRequest _request =(HttpServletRequest) request;
		HttpServletResponse _response = (HttpServletResponse)response;
		HttpSession session = _request.getSession();
		Object fadminAid = session.getAttribute("fadmin");
		if(fadminAid!=null){
			chain.doFilter(_request, _response);
		}else{
			_request.setAttribute("msg", "您还未登录，请登录后再访问!");
			_request.setAttribute("url", "/login.jsp");
			_request.getRequestDispatcher("/pages/forward.jsp").forward(_request, _response);
		}
	}

	@Override
	public void destroy() {

	}

}
